package apriorialgo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class C1ItemsetMapper extends
		Mapper<LongWritable, Text, Text, IntWritable> {

	@Override
	public void map(LongWritable key, Text value, Context context)
			throws IOException {		
		String line = value.toString();
		StringTokenizer tokenizer = new StringTokenizer(line);
		List<String> candidateItemset = new ArrayList<String>();		
		while (tokenizer.hasMoreTokens()) {	
			String token = tokenizer.nextToken();
			token.trim();
			if (candidateItemset.contains(token)) {
				continue;
			}
			candidateItemset.add(token);
			try {
				context.write(new Text(token), new IntWritable(1));
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}